<?php

namespace App\Admin\Extensions\Column\User;

use App\Models\User\SystemUser;
use Encore\Admin\Admin;
use Encore\Admin\Grid\Displayers\AbstractDisplayer;

/**
 * 父级数据
 * Class Parentinfo
 * @package App\Admin\Extensions\Column
 */
class Parentinfo extends AbstractDisplayer
{
    public function display()
    {
        if ($this->value) {
            $user  = SystemUser::query()->find($this->value);
            if ($user) {
                return $this->modal($user);
            } else {
                return '无此用户ID：'.$this->value;
            }

        }
        else  {
            return '无';
        }
    }

    public function modal($value)
    {
        $comment =   SystemUser::COMMENT;
        $comment = collect($comment);

        return <<<EOT
        
<a style="cursor:pointer;" data-toggle="modal" data-target="#exampleModal_parent_{$value->id}">
  <small>查看</small> 
</a>
<!-- Modal -->
<div class="modal fade" id="exampleModal_parent_{$value->id}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">信息</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
          <div class="row">
            <div class="col-md-2">{$this->trans('SystemUser.nickname') }:</div>
            <div class="col-md-8"> {$value->nickname} </div>
          </div>
          <div class="row">
            <div class="col-md-2">{$this->trans('SystemUser.username')}:</div>
            <div class="col-md-8"> {$value->username} </div>
          </div>
           <div class="row">
            <div class="col-md-2">{$this->trans('SystemUser.phone')}:</div>
            <div class="col-md-8"> {$value->phone} </div>
          </div>

          <div class="row">
            <div class="col-md-2">{$this->trans('SystemUser.avatar_url')}:</div>
            <div class="col-md-8"> {$value->avatar_url} </div>
          </div>

          <div class="row">
            <div class="col-md-2">{$this->trans('SystemUser.email')}:</div>
            <div class="col-md-8"> {$value->email} </div>
          </div>

          <div class="row">
            <div class="col-md-2">{$this->trans('SystemUser.wallet')}:</div>
            <div class="col-md-8"> {$value->wallet} </div>
          </div>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
<!--        <button type="button" class="btn btn-primary">Save chagnes</button>-->
      </div>
    </div>
  </div>
</div>

EOT;

    }

    public function trans($key)
    {
        return trans($key);
    }
}
